var app = angular.module('myApp',[]);
app.controller('affirm2Ctrl',function($scope,$http,$timeout){
	
	
	$('.default-addr').each(function(i,e){
		$(e).click(function(){
			$('.affirm-total-addlist').find('.affirm-moren').hide();
			$(this).parent().siblings().find('.affirm-moren').show();
			$('.affirm-radio').attr('src','../img/jifendingdan/circle0.png');
			$(this).parent().siblings().find('.affirm-radio').attr('src','../img/jifendingdan/circle1.png');
			$('.default-addr').show();
			$(this).hide();
		})	
	})
	
	//点击更换发票类型
	$('.bill-radio').each(function(i,e){
		$(e).click(function(){
			$('.bill-radio').removeClass('on');
			$(this).addClass('on');
		})
	})
	
	//定义一个布尔值
	var flag1 = true;
	$('.other-addr').click(function(){
		flag1=!flag1;
		var len = $('.affirm-total-addlist').length; 
		if(flag1==false){
			$('.affirm-total-addr').height($('.affirm-total-addlist').get(0).offsetHeight*len+ len*10)
			$('.other-show').hide();
			$('.other-hide').show();
		}else{
			$('.affirm-total-addr').css('overflow','hidden');
			$('.other-show').show();
			$('.other-hide').hide();
			$('.affirm-total-addr').height(190);
		}
	})
	
	//点击修改,弹出时间框
	$scope.show1 = false;
	$scope.changeTime = function(){
		$scope.show1 = !$scope.show1;
	}
	
	//点击th更改配送时间
	$('.change-time th').each(function(i,e){
		$(e).click(function(){
			
			$('.change-time th').removeClass('choosed');
			$(this).addClass('choosed');
			var that=this;
			$scope.confirm = function(){
				$('.send-time2').html($(that).html());
				$scope.show1 = false;
			}
			$scope.cansel = function(){
				$scope.show1 = false;
			}
		})
	})
	
	//点击使用新地址,跳出编辑地址弹框
	$scope.show2 = false;
	$scope.addNew = function(){
		$scope.show2 = !$scope.show2;
	}
	//更新修改地址的弹框
	$scope.flag3 = false;
	$scope.edit=function(){
		$scope.flag3=!$scope.flag3;
		if($scope.flag3==true){
			$('#edit-radio').addClass('on');
			$('#edit-radio').removeClass('edit-radio');
		}else{
				$('#edit-radio').removeClass('on');
				$('#edit-radio').addClass('edit-radio');
		}
	}
	
	//点击返回按钮和保存按钮进行相应操作
	$scope.return1= function(e){//返回
		$scope.show2=!$scope.show2;
	}
	$scope.save1 = function(){//保存填写到的信息提交到数据库中.
		
	}
	//地址三级联动
	var sheng = document.getElementById('sheng');
	var shi = document.getElementById('shi');
	var xian = document.getElementById('xian');

	function shengFun(){
		var l = provinceList.length;
		var shtml = '';
		for(var i=0;i<l;i++){
			shtml+='<option value='+i+'>'+provinceList[i].name+'</option>';
		}
		sheng.innerHTML = shtml;
		cityFun(0);
	}

	function cityFun(n){
		var city = provinceList[n].cityList;
		var l = city.length;
		var shtml = '';
		for(var i=0;i<l;i++){
			shtml+='<option value='+i+'>'+city[i].name+'</option>';
		}
		shi.innerHTML = shtml;
		xianFun(n,0);
	}

	function xianFun(n,m){
		var city = provinceList[n].cityList[m].areaList;
		var l = city.length;
		var shtml = '';
		for(var i=0;i<l;i++){
			shtml+='<option>'+city[i]+'</option>';
		}
		xian.innerHTML = shtml;
	}

	//设置默认
	shengFun();
	
	//点击效果
	sheng.onchange=function(){
		var n = this.selectedIndex;
		cityFun(n);
		shi.onchange=function(){
			var m = this.selectedIndex;
			xianFun(n,m);
		};
	};
	
	
	
	
	
	
	
	
	
	
	
	
})